/*######################################################################################
### Replication file for Congressional Representation by Petition:                   ###
### Assessing the Voices of the Voteless in a Comprehensive New Database, 1789-1949  ###
###                                                                                  ###
### Authors: Maggie Blackhawk, Daniel Carpenter, Tobias Resch and Benjamin Schneer   ###
###                                                                                  ###
### File: contours_replication3.do                                                   ###
######################################################################################*/

*install ados
*ssc install outreg2
*ssc install coefplot 

* Do-file for replication of numbers and descriptive estimates reported in "Contours of Representation by Petition" (2020)
clear all

cd "~/replication"

*load data

use "data/CPD.dta", clear


* Start with basic counts and tabling probabilities for Native Americans

count if Nativepetitioner == 1
count if possnonNativecodedNative == 1


* Table A-5
xtreg Nativepetitioner year1812to1840 year1841to1865 year1866to1900 year1901to1918 yearafter1918, robust
outreg2 using figs/contoursNativeoutreg01.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
xtreg Nativepetitioner year1812to1840 year1841to1865 year1866to1900 year1901to1918 yearafter1918, fe i(statenum) cluster(statenum)
outreg2 using figs/contoursNativeoutreg01.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
cloglog Nativepetitioner year1812to1840 year1841to1865 year1866to1900 year1901to1918 yearafter1918, robust
outreg2 using figs/contoursNativeoutreg01.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
logit Nativepetitioner year1812to1840 year1841to1865 year1866to1900 year1901to1918 yearafter1918, or robust
outreg2 using figs/contoursNativeoutreg01.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append


*Table A-6
xtreg Nativepetitioner region_Midwest region_South region_bordersouth region_West if(statemissing == 0), fe i(yearcongindex) cluster(yearcongindex)
outreg2 using figs/contoursNativeoutreg02.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
logit Nativepetitioner region_Midwest region_South region_bordersouth region_West if(statemissing == 0), or
outreg2 using figs/contoursNativeoutreg02.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
xtreg Nativepetitioner region_Midwest region_South region_bordersouth region_West if(statemissing == 0 & postCivilWar == 0), fe i(yearcongindex) cluster(yearcongindex)
outreg2 using figs/contoursNativeoutreg02.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
xtreg Nativepetitioner region_Midwest region_South region_bordersouth region_West if(statemissing == 0 & postCivilWar == 1), fe i(yearcongindex) cluster(yearcongindex)
outreg2 using figs/contoursNativeoutreg02.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
logit Nativepetitioner region_Midwest region_South region_bordersouth region_West if(statemissing == 0 & postCivilWar == 0), or
outreg2 using figs/contoursNativeoutreg02.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
logit Nativepetitioner region_Midwest region_South region_bordersouth region_West if(statemissing == 0 & postCivilWar == 1), or
outreg2 using figs/contoursNativeoutreg02.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append

*Figure 4
** Now do some coefficient plotting (make sure coefplot is installed in STATA)

label var yearbefore1812 "Before 1812"
label var year1812to1840 "1812 -- 1840"
label var year1841to1865 "1841 -- 1865"
label var year1866to1900 "1866 -- 1900"
label var year1901to1918 "1901 -- 1918"
label var yearafter1918 "After 1918"

reg Nativepetitioner100 yearbefore1812 year1812to1840 year1841to1865 year1866to1900 year1901to1918 yearafter1918, robust noconstant

coefplot, xscale( range (0 0.5))  xlabel(0 "0" 0.1 "0.1" 0.2 "0.2" 0.3 "0.3" 0.4 "0.4" 0.5 "0.5")  graphregion(fcolor(white)) xtitle(Percentage of period petitions authored by Native Americans) scheme(s1mono)
graph export "figs/fig4.png", replace

**Figure 5

label var region_East "East"
label var region_West "West"
label var region_Midwest "Midwest"
label var region_South "South"

reg Nativepetitioner100 region_East region_Midwest region_South region_West if(statemissing == 0 & postCivilWar == 0), noconstant
estimates store Native01preCW

reg Nativepetitioner100 region_East region_Midwest region_South region_West if(statemissing == 0 & postCivilWar == 1), noconstant
estimates store Native01postCW

coefplot Native01preCW, bylabel(1789-1865) || Native01postCW, bylabel(1866-1949) ///
      ||, drop(_cons) xline(0) xscale( range (0 0.5)) byopts(compact cols(1)) graphregion(fcolor(white)) xtitle(Percentage of period petitions authored by Native Americans) scheme(s1mono)
	  
graph export "figs/fig5.png", replace

*Women's petitioning

* Now code and descriptively analyse women's petitions
*Table 3
sum womanpetitioner_estimate*
sum womanpetitioner_estimate* if(year1921andafter == 0)
sum	womanpetitioner_estimate* if(year1921andafter == 1)



* First do women's petitioning over time.  Note that the logits, when estimated, do not converge, so we stick with linear regressions

*Table A-7
xtreg womanpetitioner_estimate01 year1812to1840 year1841to1865 year1866to1900 year1901to1918 yearafter1918, fe i(statenum) cluster(statenum)
outreg2 using figs/contourswomanoutreg01.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
xtreg womanpetitioner_estimate02 year1812to1840 year1841to1865 year1866to1900 year1901to1918 yearafter1918, fe i(statenum) cluster(statenum)
outreg2 using figs/contourswomanoutreg01.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
xtreg womanpetitioner_estimate03 year1812to1840 year1841to1865 year1866to1900 year1901to1918 yearafter1918, fe i(statenum) cluster(statenum)
outreg2 using figs/contourswomanoutreg01.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append


* Now turn to women by region over time.  Logit models converge here, so we include them

*Table A-8

xtreg womanpetitioner_estimate01 region_Midwest region_South region_bordersouth region_West if(statemissing == 0), fe i(yearcongindex) cluster(yearcongindex)
outreg2 using figs/contourswomanoutreg02.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
logit womanpetitioner_estimate01 region_Midwest region_South region_bordersouth region_West if(statemissing == 0), or
outreg2 using figs/contourswomanoutreg02.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
xtreg womanpetitioner_estimate01 region_Midwest region_South region_bordersouth region_West if(statemissing == 0 & postCivilWar == 0), fe i(yearcongindex) cluster(yearcongindex)
outreg2 using figs/contourswomanoutreg02.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
xtreg womanpetitioner_estimate01 region_Midwest region_South region_bordersouth region_West if(statemissing == 0 & postCivilWar == 1), fe i(yearcongindex) cluster(yearcongindex)
outreg2 using figs/contourswomanoutreg02.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
logit womanpetitioner_estimate01 region_Midwest region_South region_bordersouth region_West if(statemissing == 0 & postCivilWar == 0), or
outreg2 using figs/contourswomanoutreg02.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
logit womanpetitioner_estimate01 region_Midwest region_South region_bordersouth region_West if(statemissing == 0 & postCivilWar == 1), or
outreg2 using figs/contourswomanoutreg02.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append

*Table A-9

xtreg womanpetitioner_estimate02 region_Midwest region_South region_bordersouth region_West if(statemissing == 0), fe i(yearcongindex) cluster(yearcongindex)
outreg2 using figs/contourswomanoutreg03.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
logit womanpetitioner_estimate02 region_Midwest region_South region_bordersouth region_West if(statemissing == 0), or
outreg2 using figs/contourswomanoutreg03.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
xtreg womanpetitioner_estimate02 region_Midwest region_South region_bordersouth region_West if(statemissing == 0 & postCivilWar == 0), fe i(yearcongindex) cluster(yearcongindex)
outreg2 using figs/contourswomanoutreg03.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
xtreg womanpetitioner_estimate02 region_Midwest region_South region_bordersouth region_West if(statemissing == 0 & postCivilWar == 1), fe i(yearcongindex) cluster(yearcongindex)
outreg2 using figs/contourswomanoutreg03.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
logit womanpetitioner_estimate02 region_Midwest region_South region_bordersouth region_West if(statemissing == 0 & postCivilWar == 0), or
outreg2 using figs/contourswomanoutreg03.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
logit womanpetitioner_estimate02 region_Midwest region_South region_bordersouth region_West if(statemissing == 0 & postCivilWar == 1), or
outreg2 using figs/contourswomanoutreg03.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append

*Table A-10

xtreg womanpetitioner_estimate03 region_Midwest region_South region_bordersouth region_West if(statemissing == 0), fe i(yearcongindex) cluster(yearcongindex)
outreg2 using figs/contourswomanoutreg04.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
logit womanpetitioner_estimate03 region_Midwest region_South region_bordersouth region_West if(statemissing == 0), or
outreg2 using figs/contourswomanoutreg04.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
xtreg womanpetitioner_estimate03 region_Midwest region_South region_bordersouth region_West if(statemissing == 0 & postCivilWar == 0), fe i(yearcongindex) cluster(yearcongindex)
outreg2 using figs/contourswomanoutreg04.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
xtreg womanpetitioner_estimate03 region_Midwest region_South region_bordersouth region_West if(statemissing == 0 & postCivilWar == 1), fe i(yearcongindex) cluster(yearcongindex)
outreg2 using figs/contourswomanoutreg04.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
logit womanpetitioner_estimate03 region_Midwest region_South region_bordersouth region_West if(statemissing == 0 & postCivilWar == 0), or
outreg2 using figs/contourswomanoutreg04.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append
logit womanpetitioner_estimate03 region_Midwest region_South region_bordersouth region_West if(statemissing == 0 & postCivilWar == 1), or
outreg2 using figs/contourswomanoutreg04.doc, dec(4) noaster addnote(Put your notes here.) tex(frag) append


** Now plot coefficients for women's petitioning (start with generic identity and no border South category)

*Figure 6


reg womanpetitionerx100_estimate01 region_East region_Midwest region_South region_West if(statemissing == 0 & postCivilWar == 0), noconstant
estimates store woman01preCW

reg womanpetitionerx100_estimate01 region_East region_Midwest region_South region_West if(statemissing == 0 & postCivilWar == 1), noconstant
estimates store woman01postCW

coefplot woman01preCW, bylabel(1789-1865) || woman01postCW, bylabel(1866-1949) ///
      ||, drop(_cons) xline(0) xscale( range (0 3)) byopts(compact cols(1)) graphregion(fcolor(white)) xtitle(Percentage of period petitions authored by women (generic identity)) scheme(s1mono)
graph export "figs/fig7.png", replace


reg womanpetitionerx100_estimate03 region_East region_Midwest region_South region_West if(statemissing == 0 & postCivilWar == 0), noconstant
estimates store woman03preCW

reg womanpetitionerx100_estimate03 region_East region_Midwest region_South region_West if(statemissing == 0 & postCivilWar == 1), noconstant
estimates store woman03postCW

coefplot woman03preCW, bylabel(1789-1865) || woman03postCW, bylabel(1866-1949) ///
      ||, drop(_cons) xline(0) byopts(compact cols(1)) graphregion(fcolor(white)) xtitle(Percentage of period petitions authored by women (generic, familial and named identities))  scheme(s1mono)

graph export "figs/fig6.png", replace


*Table 4
xtset topicnum
xtreg action_table Nativepetitioner womanpetitioner_estimate03 i.congressnum, fe i(topicnum) cluster(topicnum)

xtreg action_table Nativepetitioner womanpetitioner_estimate03 i.congressnum if gagruleperiod==1, fe i(topicnum) cluster(topicnum)
